package com.javaIO.demo2;

import java.io.*;

public class Test5 {
    public static void main(String[] args) {
        /**
         * FileReader   底层封装FileInputStream
         *  FileWriter与FileReader ------二次封装，不需要传递字节流对象
         *  字符缓冲流
         *  BufferedReader BufferedWriter    8192/1024 = 8k
         *  BufferedWriter 写入换行操作
         *
         */
        try {
            String fileNameWriter = "D:\\SoftDevelopment\\Java\\file\\demo\\test2.txt";
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(fileNameWriter));
            for (int i = 0; i < 10; i++) {
                bufferedWriter.write("Java" + i);
                //换行
                bufferedWriter.newLine();
            }
            bufferedWriter.close();


            BufferedReader bufferedReader = new BufferedReader(new FileReader(fileNameWriter));
            //一行一行读取   第一行
//            String s = bufferedReader.readLine();
//            System.out.println(s);
//            //第二行
//            String s1 = bufferedReader.readLine();
//            System.out.println(s1);
//            //第三行
//            String s2 = bufferedReader.readLine();
//            System.out.println(s2);

            String line;
            while ((line = bufferedReader.readLine()) != null) {
                System.out.println(line); //读取一行数据，换行输出在控制台
            }

            bufferedReader.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
